package com.changgou.order.mq.queue;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 延时队列的配置
 */

@Configuration
public class MqConfig {
    /***
     * 延时队列消息过期的时候会将消息发给orderListenerQuery
     * @return
     */
    @Bean
    public Queue orderDelayQueue(){
        /**
         * 死信队列
         * 具体的实现思路
         *
         */
        //死信交换机
       return QueueBuilder
               .durable("orderDelayQueue")
               .withArgument("x-dead-letter-exchange", "orderListenerExchange")
               .withArgument("x-dead-letter-routing-key","orderListenerQuery")
               .build();
    }

    /**
     * 队列2作用时用来接收队列的消息
     * @return @Bean(value="orderListenerQuery") 不写value默认的是方法的名字
     */
    @Bean
    public Queue orderListenerQuery(){
     return  new Queue("orderListenerQuery",true);
    }
    /**
     * 交换机
     */
    @Bean
    public Exchange orderListenerExchange(){
        return  new DirectExchange("orderListenerExchange");
    }
    //队列2orderListenerQuery绑定到交换机上
  @Bean
   public Binding orderListenerBind(Queue orderListenerQuery,Exchange orderListenerExchange){
        return  BindingBuilder.bind(orderListenerQuery).
                to(orderListenerExchange)
                .with("orderListenerQuery")
                .noargs();
   }


    //
}
